package com.coocaa.ops.admin.v1.dmp.tag.service.impl;


import com.coocaa.ops.admin.base.language.CommonLanguageProperties;
import com.coocaa.ops.admin.v1.dmp.tag.constant.DmpTagTypeConstants;
import com.coocaa.ops.admin.v1.dmp.tag.model.DmpPolicyQueryModel;
import com.coocaa.ops.admin.v1.dmp.tag.model.DmpTagInfo;
import com.coocaa.ops.admin.v1.dmp.tag.model.DmpTagQueryModel;
import com.coocaa.ops.admin.v1.dmp.tag.provider.IDmpTagQueryProvider;
import com.coocaa.ops.admin.v1.dmp.tag.service.IDmpTagQueryService;
import com.coocaa.ops.common.core.base.model.PageResultModel;
import com.coocaa.ops.common.core.base.model.R;
import com.coocaa.ops.common.tool.base.InstanceUtil;
import com.coocaa.ops.common.tool.exception.BusinessException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author bijiahao
 * @date : 2018/10/12.
 * @description
 */
@Service
public class DmpTagQueryServiceImpl implements IDmpTagQueryService {

    @Autowired
    private IDmpTagQueryProvider queryProvider;
    private static CommonLanguageProperties commonLanguageProperties;


    @Override
    public R getTagResultInfo(DmpTagQueryModel queryModel, Integer userId) throws Exception {
        if (DmpTagTypeConstants.CROWD_POLICY.equals(queryModel.getType())) {
            List<DmpTagInfo> tagInfoList = queryProvider.getTagListForCrowdPolicy(queryModel, userId);
            return R.ok(tagInfoList);
        } else if (DmpTagTypeConstants.CROWD.equals(queryModel.getType())) {
            List<DmpTagInfo> tagInfoList = queryProvider.getTagListForCrowd(queryModel, userId);
            return R.ok(tagInfoList);
        }
        Map errMap = InstanceUtil.newHashMap(1);
        errMap.put("type", queryModel.getType());
        throw new BusinessException(errMap, commonLanguageProperties.getNotTreat());
    }

    @Autowired
    public void setCommonLanguageProperties(CommonLanguageProperties commonLanguageProperties) {
        DmpTagQueryServiceImpl.commonLanguageProperties = commonLanguageProperties;
    }

    @Override
    public R getCrowdPolicyPageResult(DmpPolicyQueryModel queryModel, Integer userId) throws Exception {
        PageResultModel<DmpTagInfo> pageResult = queryProvider.getPageResultForCrowdPolicy(queryModel, userId);
        return R.ok(pageResult);
    }
}
